<script type="text/javascript">
var maxnum=5,stop=1000,Rsdata;
$.getScript("/static/thinkct/js/plupload.js", function() {
uploader = new plupload.Uploader({
//创建实例的构造方法
                runtimes: 'html5,flash,silverlight,html4', //上传插件初始化选用那种方式的优先级顺序
                browse_button: 'browse', // 上传按钮
                url: "/upload/", //上传地址
			    resize: {width: 900},  
				max_retries: 1,
                flash_swf_url: '/static/thinkct/js/Moxie.swf', //flash文件地址
                silverlight_xap_url: '/static/thinkct/js/Moxie.xap', //silverlight文件地址
                filters: {
					prevent_duplicates : true, //不允许队列中存在重复文件
                    max_file_size:'5mb', //最大上传文件大小（格式100b, 10kb, 10mb, 1gb）
                    mime_types: [//允许文件上传类型
                        {title: "选择文件", extensions:'jpg,png,gif,txt,pdf,doc,docx,xls,xlsx,zip,rar'}
                    ]
                },
                multi_selection: true //true:ctrl多文件上传, false 单文件上传
	});
	uploader.init(); //初始化
		//绑定文件添加进队列事件

	uploader.bind('FilesAdded',function(uploader,files){
	var newnum=maxnum-parseInt($('#FileListsuc>div').length+$('#FileListing tr').length),flen=files.length,fhtml,vhtml='',ehtml='';
    if(flen>newnum){ 
	// 最多上传newmaxnum
	     layer.alert("<strong>附件最多能上传"+maxnum+"个</strong>",{icon:2}); 
         uploader.splice(newnum,10000);  
        }
		for(var i = 0; i<=flen; i++){
			if(i==flen){ 
			//更新UI
			 if(ehtml!=''){layer.alert("<strong>以下附件已传过了，不要重复上传</strong><br>"+ehtml,{icon:0});}
			 if(uploader.files.length>0){
			 $('#pluing').show();
			 $(fhtml).appendTo('#FileListing');
			 $('#pluing u').html(uploader.files.length);
			 }
			 return false;
			}
			if(i>=newnum){ 
			// 最多上传newnum
			continue;
		    }
			fname=files[i].name;
			fid=files[i].id;
			var f5name=$.md5(files[i].size+files[i].lastModifiedDate+files[i].type);
			 vhtml='<tr id="file-' + fid +'"><td>' + fname +'</td><td></td><td align="center"><a onclick=deling("'+fid+'")>取消</a></td></tr>'
			 $(".upload-box :checkbox").each(function(){     
	         if($(this).val()==f5name){
             vhtml='';
			 uploader.removeFile(fid);
			 ehtml+="【"+fname+"】<br>";
			 return false;
			 }
	         });
             fhtml=fhtml+vhtml;	
		}

	});
	uploader.bind("BeforeUpload",function(uploader,file){
    uploader.setOption("multipart_params",{lastDate:file.lastModifiedDate,osize:file.size,number:'{$bh}',filebh:'{$bh}',type:'serve',filetype:'files',maxnum:maxnum}); 
    }); 

	uploader.bind("UploadProgress",function(uploader,file){
	//进度
	$('#progress-in').width(uploader.total.percent+"%"); 
	$("#file-"+file.id+" td:eq(2)").html("<b>"+file.percent+"%</b>");
    });
	uploader.bind("FileUploaded",function(uploader, file,info){
	//上传完成后
		 $('#progress-uploaded').html(uploader.total.uploaded);
		 var data =$.parseJSON(info.response);
		 if(data.state!=0){
         $fh=$('#progress ul');
         $fh.show();
		 $('<p><span>'+file.name+'</span><br><b>'+data.state+' >> 继续执行…</b></p>').appendTo($fh);
	     stop=3000;
		 }
    });
	uploader.bind("UploadComplete",function(uploader){
	//全部完成后
		setTimeout("Rs(Rsdata)",stop);
    });
		uploader.bind("Error",function(uploader,err){
		//错误提示
		 if(err.message=='HTTP Error.'){
		 fid=err.file.id;
		 $("#file-"+fid+" td:eq(1)").html("<font color=red>系统出错，代码"+err.code+"</font>");
		 $("#file-"+fid+" td:eq(2)").html('<a onclick=deling("'+fid+'")>删除</a>');
		 return false;
		 }
		 layer.alert("<strong>"+err.message+"</strong>",{icon:5});
    });

});
</script>
<style>
.item-btn{text-align:center;padding-bottom:15px;}
</style>
<form class="layui-form layui-font14 layui-serve" name="" action>
<div class="layui-form-item" style='margin-top:0;'>
<ul class="serve_top">
<li class='l1'><a href="{:c_url($serve.id,'serve')}" target="_blank" ><img src="{:get_tp($serve.bh)}" /></a></li>
<li class='l2'><p class="tit"><a href="{:c_url($serve.id,'serve')}" target="_blank">{$serve.tit}</a></p><p>服务商：<a href="{:sysconf('site_domain')}/ishop{$sell.bh}/" class="list_seller" target="_blank">{$sell.name}  {:xy($sell.rev_m,'s')}</a></p><p>服务价格：<b>{:money_tmoney($serve)}</b></p></li>
</ul>
</div>

<div class="layui-form-item" style='margin:15px 0'>
<div class="upload-box" style='margin:0 20px'>
<p>
<textarea name="txt" class="layui-textarea checkLen" lay-verify="serverequire" style='height:100px;width:96%;margin:10px 2% 0 2%' placeholder="请填写服务的具体要求、双方约定等（将作为{:sysconf('site_name')}对于服务是否完成的主要评判依据）"></textarea>
</p>

	<div class="container">
				<div class="statusBar" style='line-height:36px;'>
				<div class="info">非必传！限传5个附件,单附件大小上限5M，<a onclick="layer.alert('Jpg,Png,Gif,Txt,Pdf,Doc,Xls,Zip,Rar', {icon:1,title: '<b>支持上传以下格式</b>'});">查看支持格式</a></div>
					<div class="btns">
					<a id="browse">上传附件</a>
					</div>
				</div>
<table  class="fu_list" id='pluing' style='display:none;' >
            <thead>
              <tr>
                <td width="65%">待传队列（<u>0</u>）<font color="#888">提示：待传队列为点击最后的“确认提交”时开始上传</font></td>
				<td width="25%" align="center"></td>
                <td width="10%" align="center">操作</td>
              </tr>
            </thead>
            <tbody id="FileListing">
            </tbody>
          </table>


	</div>
</div>
</div>
<div class='serve_cart'>
{if $serve.tmoney==1}<div class="layui-form-item">
    <label class="layui-form-label">服务版本</label>
    <div class="layui-inline"><div class="layui-form-mid blue">
	{$data.edition}	</div>
	</div>
</div>{/if}

<div class="layui-form-item">
    <label class="layui-form-label">服务价格</label>
    <div class="layui-inline"><div class="layui-form-mid orange">
	￥{$data.money}.00	</div>
	</div>
</div>


{if $serve.piece==1}<div class="layui-form-item">
    <label class="layui-form-label">购买数量</label>
    <div class="layui-inline"><div class="layui-form-mid">
	<b>{$data.piece}</b> 件
	</div>
	</div>
</div>{/if}

{if $data.piece>1}<div class="layui-form-item">
    <label class="layui-form-label">合计</label>
    <div class="layui-inline"><div class="layui-form-mid orange b">
	￥<b>{$data.money*$data.piece}.00</b>
	</div>
	</div>
</div>{/if}

</div>

<div class="layui-form-item item-btn">
    <input type="button" class="layui-btn layui-btn-danger lay-submit" lay-submit="" lay-filter="addserve" value="确认提交" />
    <input type="button" class="layui-btn layui-btn-primary allmoney" number='{$data.number}' value="重新选价" />
	</div>
<input type="hidden" name="layer" value="1">
<input type="hidden" name="bh" value="{$bh}">
<input type="hidden" name="piece" value="{$data.piece}">
<input type="hidden" name="money" value="{$data.money}">
<input type="hidden" name="edition" value="{$data.edition}">
<input type="hidden" name="number" value="{$data.number}">
<input type="hidden" name="action" value="add">
<input type="hidden" name="passkey" value="{:passkey()}">
</form>
<script type="text/javascript">
layer.title('<font  style="font-weight:700;font-size:14px;">服务下单</font>');layui.use('form',function(){var form=layui.form();form.verify({serverequire:function(value){if(value.length<10){return'具体要求不能少于10个字'}}});form.on('submit(addserve)',function(data){layer.load();dform(data.field,'serveorder',function(datas){if(datas.state==1&&uploader.total.queued>0){Rsdata=datas;progress();$('#progress-upload').html(uploader.total.queued);uploader.start()}else{Rs(datas)}});return false});form.on('checkbox(delfile)',function(data){var label=$(data.elem).nextAll('label');if(data.elem.checked){label.removeClass('gray')}else{label.addClass('gray')}});$(".layui-serve .bfile img").length>0&&setTimeout(function(){$(".layui-serve .bfile").unbind();layer.photos({photos:".layui-serve .bfile",shift:5})},100);form.render('checkbox')});
</script>
